<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>部门管理</title>
    </head>
    <body>
        <div id="departmentGrid" style="height:580px;" class="x-form-item">
        </div>
        <script>
            /*
             * Ext JS Library 2.1
             * Copyright(c) 2006-2008, Ext JS, LLC.
             * licensing@extjs.com
             *
             * http://extjs.com/license
             */
            Ext.onReady(function(){
                var departmentCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    header: '编号',
                    dataIndex: 'id'
                }, {
                    header: '部门名称',
                    dataIndex: 'name'
                }, {
                    header: '区域',
                    dataIndex: 'area'
                }]);
                //隐藏系统编号
                departmentCM.setHidden(1, !departmentCM.isHidden(1));
                var departmentDS = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getAllDepartments'
                    }),
                    reader: new Ext.data.JsonReader({
                        totalProperty: 'totalProperty',
                        root: 'root'
                    }, [{
                        name: 'id'
                    }, {
                        name: 'name'
                    }, {
                        name: 'area'
                    }])
                });
                /************************************************************
                 * Define menubar now in here
                 *   add and delete functions
                 ************************************************************/
                var menubar = [{
                    text: '增加部门',
                    tooltip: '增加部门',
                    iconCls: 'addItem',
                    handler: function(){
                        // add new costlevel now - action
                        CreateDepartment(departmentDS);
                    }
                }, '-', {
                    text: '删除部门',
                    tooltip: '删除部门',
                    iconCls: 'remove',
                    handler: function(){
                        // delete costlevel now - action
                        DeleteDepartment(departmentDS, departmentGridPanel);
                    }
                }, '-', {
                    text: '编辑部门',
                    tooltip: '编辑部门',
                    iconCls: 'editItem',
                    handler: function(){
                        // delete costlevel now - action
                        EditDepartment(departmentDS, departmentGridPanel);
                    }
                }];
                var departmentGridPanel = new Ext.grid.GridPanel({
                    el: 'departmentGrid',
                    ds: departmentDS,
                    cm: departmentCM,
                    collapsible: true,
                    animCollapse: false,
                    title: '部门列表',
                    tbar: menubar,
                    loadMask: true
                });
                departmentGridPanel.render();
                //ds.load();
                departmentDS.load();
                
            });
            
        </script>
    </body>
</html>
